<template>
	<view class="mainpadding2">
		<view class="tab_nav">
			<view class="navTitle" v-for="(item,index) in navList" :key="index">
				<view :class="{'active':isActive === index}" @click="checked(index)">
					{{item.title}}
				</view>
			</view>
		</view>
		<template v-if="isActive==0">
			<view class="margin_top flexbetween" v-for="item in list.data" :key="item.id" @click="jumpzhuye(item.user1.id)">
				<view class="flexleft" style="width: 73%;">
					<image class="touxiang margin_right2" :src="item.user1.avatar_text" mode=""></image>
					<view class="">
						<view class="sanshier fonweight">{{item.user1.nickname}}</view>
						<view class="xiankuan xiaohui strongtext margin_top1 xiankuan" v-if="item.user1.bio">{{item.user1.bio}}</view>
						<view class="xiankuan xiaohui strongtext margin_top1 xiankuan" v-else>这个人很懒，什么也没留下！</view>
					</view>
				</view>
				<view class="dhbtn" v-if="item.is_gz==1" @click.stop="cancelguanzhufn(item.user_id,item)">已关注</view>
				<!-- <view class="dhbtn">互相关注</view> -->
				<view class="dlbtn" v-if="item.is_gz==0 && user_id!=item.user_id" @click.stop="guanzhufn(item.user_id,item)">关注</view>
				<!-- <view class="dlbtn">回关</view> -->
			</view>
		</template>
		<template v-else>
			<view class="margin_top flexbetween" v-for="item in list.data" :key="item.id" @click="jumpzhuye(item.user_id)">
				<view class="flexleft" style="width: 73%;">
					<image class="touxiang margin_right2" :src="item.user.avatar_text" mode=""></image>
					<view class="">
						<view class="sanshier fonweight">{{item.user.nickname}}</view>
						<view class="xiankuan xiaohui strongtext margin_top1" v-if="item.user.bio">{{item.user.bio}}</view>
						<view class="xiankuan xiaohui strongtext margin_top1" v-else>这个人很懒，什么也没留下！</view>
					</view>
				</view>
				<view class="dhbtn" v-if="item.is_gz==1" @click.stop="cancelguanzhufn(item.user_id,item)">已关注</view>
				<!-- <view class="dhbtn">互相关注</view> -->
				<view class="dlbtn" v-if="item.is_gz==0 && user_id!=item.user_id" @click.stop="guanzhufn(item.user_id,item)">关注</view>
				<!-- <view class="dlbtn">回关</view> -->
			</view>
		</template>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				isActive: 0,
				navList: [{
					index: 0,
					title: '关注'
				}, {
					index: 1,
					title: "粉丝"
				}],
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				listid:"",
				user_id:""
			}
		},
		onLoad(options) {
			let data = JSON.parse(decodeURIComponent(options.msg))
			this.isActive = data.type
			this.listid = data.id
			uni.setNavigationBarTitle({
				title: data.name
			});
			this.init()
			this.getDetail()
			this.$forceUpdate()
		},
		onShow() {
			this.user_id = uni.getStorageSync("user_id")
		},
		methods: {
			getDetail(){
				httpRequest.request('/api/index/userPage','GET',{
					id:this.listid,
				}).then(res => {
					this.navList[0].title = "关注"+res.data.mygz_num
					this.navList[1].title = "粉丝"+res.data.myfs_num
				})
			},
			guanzhufn(b_user_id,item) {
				httpRequest.request('/api/user/clUserGz', 'GET', {
					b_user_id
				}).then(res => {
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						item.is_gz = 1
					}
				})
			},
			cancelguanzhufn(b_user_id,item) {
				httpRequest.request('/api/user/clUserGz', 'GET', {
					b_user_id
				}).then(res => {
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						item.is_gz = 0
					}
				})
			},
			init(isPage, page) {
				let _this = this
				let url = "/api/user/getUserPageGzIndex"
				let data = {
					page: page || 1,
					limit: _this.limit,
					user_id: this.listid
				}
				console.log(data,uni.getStorageSync("token"));
				if(this.isActive==1){
					url = "/api/user/getUserPageFsIndex"
				}
				httpRequest.request(url, 'GET', data, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			checked(index) {
				this.isActive = index
				this.list = {}
				this.init()
			},
		}
	}
</script>

<style lang="scss" scoped>
	.dlbtn {
		background: #2361FF;
		border-radius: 44rpx;
		padding: 16rpx 40rpx;
		color: #fff;
		font-size: 24rpx;
	}

	.dhbtn {
		background: #F5F5F5;
		border-radius: 44rpx;
		padding: 16rpx 40rpx;
		color: #333;
		font-size: 24rpx;
	}

	.touxiang {
		width: 100rpx;
		height: 100rpx;
		border-radius: 50%;
	}

	.tab_nav {
		background-color: #fff;
		display: flex;
		justify-content: center;
		align-items: center;
		padding-bottom: 11rpx;
	}

	.tab_nav .navTitle {
		height: 90rpx;
		line-height: 90rpx;
		width: 100%;
		text-align: center;
		font-size: 30rpx;
		font-weight: bold;
		color: #999999;
	}

	.active {
		font-size: 30rpx;
		color: #333333;
		font-weight: bold;
		position: relative;
	}

	.active::after {
		content: "";
		position: absolute;
		width: 36rpx;
		height: 6rpx;
		background: #2361FF;
		border-radius: 3rpx;
		background-size: 100% 100%;
		left: 0rpx;
		right: 0rpx;
		bottom: 0rpx;
		margin: auto;
	}
</style>